home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + h_array.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
- //------------------------------------------------------------------------------
- // h_array
- //
- // Stefan Naeher (1989)
- //------------------------------------------------------------------------------
- #ifndef HARRAYH
- #define HARRAYH
-
- #include <LEDA/basic.h>
- #include <LEDA/slist.h>
- #include <LEDA/dp_hashing.h>
-
- #define h_array(itype,etype) name3(itype,etype,h_array)
-
- #define h_arraydeclare2(itype,etype)\
- \
- class h_array(itype,etype) : public dphash {\
- \
- void copy_key(ent& x) { x = Copy(*(itype*)&x); }\
- void copy_inf(ent& x) { x = Copy(*(etype*)&x); }\
- void clear_key(ent& x) { Clear(*(itype*)&x); }\
- void clear_inf(ent& x) { Clear(*(etype*)&x); }\
- \
- etype init;\
- SLIST def_list;\
- \
- public:\
- \
- etype& operator[](itype y) { stp i=dphash::lookup(Ent(y));\
- if (i==nil) { i=dphash::insert(Ent(y),Ent(init));\
- def_list.append(Ent(y)); }\
- return *(etype*)&dphash::info(i); }\
- /*\
- etype operator[](itype y) const\
- { stp i=dphash::lookup(Ent(y));\
- if (i==nil) return init;\
- else return etype(dphash::info(i)); }\
- */\
- bool defined(itype y) { return dphash::member(Ent(y)); }\
- \
- void init_iterator() { def_list.init_iterator(); }\
- bool next_index(itype& y){ return def_list.next_element(*(ent*)&y); }\
- \
- h_array(itype,etype)() { }\
- h_array(itype,etype)(int n,itype* I,etype* E): dphash(n,(ent*)I,(ent*)E) { }\
- h_array(itype,etype)(etype i) { init=i; }\
- h_array(itype,etype)(h_array(itype,etype)& A): dphash((dphash&)A)\
- { init = A.init; }\
- ~h_array(itype,etype)() { def_list.clear(); };\
- };
-
- #define forall_defined(i,A) for ((A).init_iterator(); (A).next_index(i); )
-
-
- #endif
-